package com.wenyu.wenyuyuedu.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.bean.circle.MyCircleBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/28.
 * 书圈--我的--的界面
 */

public class MyCircleAdapter extends BaseAdapter {

    private Context context;
    private List<MyCircleBean.InfoBean> info = new ArrayList<>();
    private MyCircleHolder holder;
    private View inflate;

    public MyCircleAdapter(Context context, List<MyCircleBean.InfoBean> info) {
        this.context = context;
        this.info = info;
    }

    @Override
    public int getCount() {
        return info.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        holder = null;
        if (view == null) {
            holder = new MyCircleHolder();
            view = View.inflate(context, R.layout.my_circle_item, null);
            holder.iv_mycircle_pictru = (ImageView) view.findViewById(R.id.iv_mycircle_pictru);
            holder.iv_mycircle_reddot = (ImageView) view.findViewById(R.id.iv_mycircle_reddot);
            holder.tv_mycircle_name = (TextView) view.findViewById(R.id.tv_mycircle_name);
            view.setTag(holder);
        } else {
            holder = (MyCircleHolder) view.getTag();
        }
        MyCircleBean.InfoBean infoBean = info.get(i);
        String update = infoBean.getUpdate();
        int updataCount = Integer.parseInt(update);
        if (updataCount == 1) {
            holder.iv_mycircle_reddot.setVisibility(View.VISIBLE);
        } else if(updataCount == 0) {
            holder.iv_mycircle_reddot.setVisibility(View.INVISIBLE);
        }
        Glide.with(context)
                .load(infoBean.getCover())
                .into(holder.iv_mycircle_pictru);
        holder.tv_mycircle_name.setText(infoBean.getTitle());

        return view;
    }

    class MyCircleHolder {
        ImageView iv_mycircle_pictru, iv_mycircle_reddot;
        TextView tv_mycircle_name;
    }

    public void addAll(List<MyCircleBean.InfoBean> info) {
        if (info != null) {
            this.info = info;
            this.info.addAll(info);
            notifyDataSetChanged();
        }
    }
}
